package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.exception.YyghException;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.result.Result;
import com.atguigu.yygh.vo.hosp.HospitalSetQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @AUTHOR: taotao
 * @DATE: 2024/1/10 16:38
 * @Description:
 */
@RestController
@RequestMapping("/admin/hosp/hospitalSet")
@Api(tags = "医院设置")
public class HospitalSetController {

    @Autowired
    private HospitalSetService hospitalSetService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询所有设置")
    public Result findAllHospitalSet() {
        List<HospitalSet> list = hospitalSetService.list();
        return Result.ok(list);
    }

    @DeleteMapping("{id}")
    @ApiOperation(value = "逻辑删除删除医院设置")
    public Result removeHospSet(@PathVariable Long id) {
        boolean flag = hospitalSetService.removeById(id);
        return flag ? Result.ok() : Result.fail();
    }

    @PostMapping("findPage/{current}/{limit}")
    @ApiOperation(value = "分页查询医院设置")
    public Result findPageHospSet(@PathVariable long current,
                                  @PathVariable long limit,
                                  @RequestBody(required = false) HospitalSetQueryVo hospitalSetQueryVo) {
        Page<HospitalSet> hospitalSetPage = hospitalSetService.findPageHospSet(current, limit, hospitalSetQueryVo);
        return Result.ok(hospitalSetPage);
    }

    @PostMapping("saveHospitalSet")
    @ApiOperation(value = "添加医院设置")
    public Result saveHospitalSet(@RequestBody HospitalSet hospitalSet) {
        boolean flag = hospitalSetService.saveHospitalSet(hospitalSet);
        return flag ? Result.ok() : Result.fail();
    }

    @GetMapping("getHospitalSet/{id}")
    @ApiOperation(value = "根据id获取医院设置")
    public Result getHospitalSet(@PathVariable Long id) {
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        return Result.ok(hospitalSet);
    }

    @PostMapping("updateHospitalSet")
    @ApiOperation(value = "修改医院设置")
    public Result updateHospitalSet(@RequestBody HospitalSet hospitalSet) {
        boolean flag = hospitalSetService.updateById(hospitalSet);
        return flag ? Result.ok() : Result.fail();
    }

    @DeleteMapping("batchRemoveHospitalSet")
    @ApiOperation(value = "批量删除医院设置")
    public Result batchRemoveHospitalSet(@RequestBody List<Long> idList) {
        hospitalSetService.removeByIds(idList);
        return Result.ok();
    }

    @PutMapping("lockHospitalSet/{id}/{status}")
    @ApiOperation(value = "医院设置锁定和解锁")
    public Result lockHospitalSet(@PathVariable Long id,
                                  @PathVariable Integer status) {
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        hospitalSet.setStatus(status);
        hospitalSetService.updateById(hospitalSet);
        return Result.ok();
    }

    @PutMapping("sendKey/{id}")
    @ApiOperation(value = "发送签名密钥")
    public Result sendKey(@PathVariable Long id) {
        HospitalSet hospitalSet = hospitalSetService.getById(id);
        String signKey = hospitalSet.getSignKey();
        String hoscode = hospitalSet.getHoscode();
        //TODO 发送短信
        return Result.ok();
    }
}
